<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Jedrzej\Pimpable\PimpableTrait;
use Illuminate\Database\Eloquent\softDeletes;
class LiveProduct extends Model
{
    use HasFactory;
    use PimpableTrait;
    use SoftDeletes;



    /**
     *允许批量赋值的字段
     */
    public $fillable = [
        'product_id',
        'audit_id',
        'cover_url',
        'url',
        'sort'
    ];

    /**
     * 可搜索的字段
     */
    public $searchable = [
        'audit_status',
        'is_show'
    ];

    /**
     *可排序字段
     */
    public $sortable = [
        'created_at',
        'id',
        'live_price',
        'audit_status',
        'is_show',
    ];

    /**
     * 默认倒序
     */
    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 价格类型枚举
     */
    public  $priceTypeEnum = [
        'price' => '一口价',
        'priceRange' => '价格区间',
        'discountPrice' => '折扣价',
    ];

    /**
     * 审核状态枚举
     */
    public  $auditStatusEnum = [
        'notApproved' => '未审核',
        'review' => '审核中',
        'approved' => '审核通过',
        'auditFailed' => '审核失败',
    ];

    /**
     * 关联商品模型
     */

    public function product()
    {
        return $this->belongsTo(Product::class, 'product_id', 'id');
    }

    /**
     * 关联后台管理员模型
     */

    public function systemAdmin()
    {
        return $this->belongsTo(SystemAdmin::class, 'audit_id', 'id');
    }

    /**
     * 多对多关联
     */
    public function liveRoom()
    {
        return $this->belongsToMany(LiveRoom::class, 'id', 'live_product_id', 'live_room_id');
    }

}
